<?php
require_once 'EZend/Controller/WebBaseController.php';

class ArticleController extends WebBaseController {
	
	public function indexAction() {
		$articleId =(int) $this->getRequest()->getParam('articleId');
		$article = $this->getCmsArticleService()->get($articleId);
		if (!$article) return $this->showNotice('找不到文章，请返回重试');
		
		$currentCategory = $this->getCmsArticleService()->getCategory($article['category_id']);
		$secondLevelCategory = $currentCategory['parent_id'] ? $this->getCmsArticleService()->getCategory($currentCategory['parent_id']) : $currentCategory;
		
		$this->view->assign('currentCategory', $currentCategory);
		$this->view->assign('secondLevelCategory', $secondLevelCategory);
		$this->view->assign('article', $article);
		
		$this->view->assign('navigates', $this->getCmsArticleService()->listTopCategories());
	}
	
	
	private function getCmsArticleService() {
		require_once 'Models/Cms/Service/CmsServiceFactory.php';
		return CmsServiceFactory::getInstance()->createCmsArticleService();
	}
}

